package main

import (
	"fmt"
	"math/rand"
	"time"
)

func bubbleSort(intSlice []int) []int {
	for i:=0 ; i<len(intSlice) - 1 ; i++{
		for j := 0 ; j < len(intSlice) - 1 - i; j ++ {
			if intSlice[j] > intSlice[j+1] {
				intSlice[j] += intSlice[j+1]
				intSlice[j+1] = intSlice[j] - intSlice[j+1]
				intSlice[j] -= intSlice[j+1]
			}
		}
	}
	return intSlice
}

func main(){
	var needSortSlice []int
	sliceLen := 10
	time.Now().UnixNano()
	rand.Seed(time.Now().UnixNano())
	for i := 0 ; i < sliceLen ; i++ {
		needSortSlice = append(needSortSlice, rand.Intn(100) )
	}
	fmt.Println("排序前 slice=", needSortSlice)
	fmt.Println("排序后 slice=", bubbleSort(needSortSlice))
}